//
//  OTCalenderViewController.m
//  OT_OC
//
//  Created by yunmian on 2019/7/17.
//  Copyright © 2019 James. All rights reserved.
//

#import "OTCalenderViewController.h"
#import "CalenderView.h"
#import "CalenderOTModel.h"

@interface OTCalenderViewController ()<CalenderViewDelete, OTNavBarDelegate>
@property (nonatomic, strong) CalenderView *calenderView;
@end

@implementation OTCalenderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}

- (void)initUI {
    self.view.backgroundColor = UIColor.whiteColor;
    
    OTNavBar *navBar = [OTNavBar createNavBar];
    navBar.type = OTNavBarTypeAdd;
    navBar.delegate = self;
    navBar.title = @"日历";
    navBar.rightTitle = @"完成";
    [self.view addSubview:navBar];

//    NSMutableArray *OTDatas = [NSMutableArray array];
//
//    CalenderOTModel *model1 = [CalenderOTModel new];
//    model1.OTDate = @"2019-07-16";
//    model1.OTDuration = @"8";
//
//    CalenderOTModel *model4 = [CalenderOTModel new];
//    model4.OTDate = @"2018-01-12";
//    model4.OTDuration = @"2";
//
//    CalenderOTModel *model2 = [CalenderOTModel new];
//    model2.OTDate = @"2019-07-15";
//    model2.OTDuration = @"3";
//
//    CalenderOTModel *model3 = [CalenderOTModel new];
//    model3.OTDate = @"2019-06-12";
//    model3.OTDuration = @"14";
//
//    [OTDatas addObject:model1];
//    [OTDatas addObject:model4];
//    [OTDatas addObject:model2];
//    [OTDatas addObject:model3];
    
    self.calenderView = [[CalenderView alloc] initWithFrame:CGRectMake(0, k_Height_NavBar, kScreenWidth, kScreenHeight - k_Height_NavBar) startDay:@"2018-1-10" endDay:@"2019-07-20" selectedDates:self.OTDates];
    self.calenderView.delegate = self;
    self.calenderView.yearMonthFormat = @"%zd年%02zd月";
    self.calenderView.actvityColor = YES;
    self.calenderView.showWeekBottomLine = YES;
    [self.view addSubview:self.calenderView];
}

#pragma mark CalenderViewDelete
-(void)calenderView:(NSIndexPath *)indexPath dateString:(NSString *)dateString {
    NSLog(@"%@",dateString);
}

#pragma mark OTNavBarDelegate
- (void)navBarDidSelectedRight {
    
    NSArray *data = self.calenderView.OTDatas;
    
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"OTDate" ascending:NO];
    NSArray *sortArray = [data sortedArrayUsingDescriptors:@[sortDescriptor]];
    
    if ([self.delegate respondsToSelector:@selector(calenderViewDidSelectedDates:)]) {
        [self.delegate calenderViewDidSelectedDates:sortArray];
    }
    
//    [data enumerateObjectsUsingBlock:^(CalenderOTModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
//
//    }];

    [self zw_toLastViewController];
}

@end
